package com.practice.car.cardataapp.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.practice.car.cardataapp.entity.BrandSales;
import com.practice.car.cardataapp.entity.frontEnd.Form;
import com.practice.car.cardataapp.mapper.BrandSalesDao;
import com.practice.car.cardataapp.service.CarBrandSaleService;
import lombok.Data;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * car-data-app project
 *
 * @author ZhangMingXing
 * @date 2020/9/7
 */
@Service
public class CarBrandSaleServiceImpl extends ServiceImpl<BrandSalesDao,BrandSales> implements CarBrandSaleService {
	@Override
	public List<Form> getSeries() {
		List<BrandSales> list = this.list();
		list.sort((a,b)->b.getSale()-a.getSale());
		SeriesUtil<BrandSales> util = new SeriesUtil<>();
		util.setLegendSolver(BrandSales::getBrand);
		util.setFormSolver(e->e);
		return util.getSeries(list);
	}
	@Data
	class Tuple {
		private long sale;
		private double proportion;

		public Tuple(long sale, double proportion) {
			this.sale=sale;
			this.proportion = proportion;
		}
	}
}
